package net.sparrow.util;

public class SpAnimation {

	
	public double a,b,c;
	public long startTime = 0;
	public boolean finished = true;
	public SpAnimation(double duration, double endPt) {
		c = endPt;
		b = duration;
		a = -(c / (b * b));
	}
	
	public SpAnimation(double duration, double endPt, long istartTime) {
		this(duration, endPt);
		startTime = istartTime;
	}
	
	public double getValue() {
		long timeSince = System.currentTimeMillis() - startTime;
		if (timeSince > b) {
			finished = true;
			return c;
		}
		return ( a * (timeSince - b) * (timeSince - b) + c);
		
	}
	
	public void resetAnimation() {
		finished = false;
		startTime = System.currentTimeMillis();
	}
	
	public SpAnimation clone() {
		return new SpAnimation(b, c, startTime);
	}
	
	// looking to make this coefficent so that the point 0,0 exists (smooth animation)
	/// y = a(x - b)^2 + c
	/// 0 = a(-b)^2 + c    // -b * -b = b^2
	//  0 = ab^2 + c
	//  -(c / b^2) = a 
}